package org.jeecg.service.service;

import org.jeecg.domain.Care;
import org.jeecg.domain.User;
import org.jeecg.mapper.CareMapper;
import org.jeecg.service.CareService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;

@Service
public class CareServiceImpl implements CareService {

    @Autowired
    private CareMapper careMapper;

    @Override
    public List<User> getCares(String username) {
        List<User> cares;
        try {
            cares = careMapper.getCares(username);
        }catch (Exception e){
            return new ArrayList<>();
        }
        return cares;
    }

    @Override
    public Boolean addCare(String username, String careUsername) {
        UUID uuid = UUID.randomUUID();
        //生成一个16位的UUID
        String id = uuid.toString().replace("-","").substring(0,16);
        Date createTime = new Date();
        Care care = new Care(id,username,careUsername,createTime);
        Integer result = careMapper.insertCare(care);
        if (result > 0){
            return true;
        }
        return false;
    }

    @Override
    public Boolean queryCare(String username, String careUsername) {
        Care care = careMapper.queryCare(username, careUsername);
        if (care != null){
            return true;
        }
        return false;
    }

    @Override
    public Boolean cancelCare(String username, String careUsername) {
        Integer result = careMapper.deleteCare(username, careUsername);
        if (result > 0){
            return true;
        }
        return false;
    }
}
